/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package orgarqsindex;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 *
 * @author Fernando Molon Toigo e Dyoni Bertuol
 */
public class TestFileGenerator {

    long rowsAmount; //quantidade de registros que serão gerados

    public TestFileGenerator() {
        rowsAmount = 100000;
    }

    boolean generate(String fileName) throws FileNotFoundException, IOException {
        File f = new File(fileName);
        if (f.exists()) {
            if (!f.delete()) {
                return false;
            }
        }
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        RowModel rm = new RowModel();
        NumberTreeNode root = new NumberTreeNode();
        String generatedRandomRow;

        for (int i = 0; i < rowsAmount;) {
            generatedRandomRow = rm.getRandomFixedRow();
            //verifica se ja nao foi inserido
            if (root.insert(generatedRandomRow.substring(rm.getRgBeginIndex(), rm.getRgBeginIndex() + rm.getRgSize()))) {
                //insere no arquivo
                raf.writeBytes(generatedRandomRow);
                i++;
            }
        }
        raf.close();

        return true;
    }
}
